﻿#region Librerias

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Printing;

#endregion


namespace ESF.WinForms.Printing
{
	public partial class uscPrintPreviewer : UserControl
	{
		#region Constructor
		
		public uscPrintPreviewer()
		{
			InitializeComponent();
		}

		#endregion


		#region Funciones

		public void SetDocument (PrintDocument pDoc, int pPageCount)
		{
			numPrintZoom.Value = 100;
			numPrintPageNumber.Value = 1;
			numPrintPageShowColumnCount.Value = 1;
			numPrintPageShowRowCount.Value = 1;
			

			if (pPageCount > 0)
			{
				Enabled = true;

				ppcPrintPreview.Document = pDoc;
				ppcPrintPreview.Visible = true;

				numPrintPageNumber.Maximum = pPageCount;
				numPrintPageShowRowCount.Maximum = pPageCount;
				numPrintPageShowColumnCount.Maximum = pPageCount;

				ppcPrintPreview.InvalidatePreview ();
			}
			else
			{
				Enabled = false;
				
				ppcPrintPreview.Visible = false;
			}
		}

		#endregion


		#region Eventos

		private void numPrintZoom_ValueChanged(object sender, EventArgs e)
		{
			ppcPrintPreview.Zoom = Math.Floor ((double) numPrintZoom.Value / 100.0);
			ppcPrintPreview.InvalidatePreview ();
		}


		private void numPrintPageNumber_ValueChanged(object sender, EventArgs e)
		{
			ppcPrintPreview.StartPage = (int) numPrintPageNumber.Value - 1;
			ppcPrintPreview.InvalidatePreview ();
		}


		private void numPrintPageShowRowCount_ValueChanged(object sender, EventArgs e)
		{
			ppcPrintPreview.Rows = (int) numPrintPageShowRowCount.Value;
			ppcPrintPreview.InvalidatePreview ();
		}


		private void numPrintPageShowColumnCount_ValueChanged(object sender, EventArgs e)
		{
			ppcPrintPreview.Columns = (int) numPrintPageShowColumnCount.Value;
			ppcPrintPreview.InvalidatePreview ();
		}

		#endregion
	}
}
